import * as Yup from "yup"


const validate = ({
	vm,
	schema,
	params
}) => {
	return new Promise((resolve, reject) => {
		vm.errors = [];
		schema.validate(params, {
			abortEarly: false
		}).then(validData => {
			resolve(true)
		}).catch(err => {
			resolve(false)
			uni.showToast({
				title: "提交内容有误,请检查填写项",
				icon: "none"
			})
			console.log(err)
			vm.errors = err.inner.map(item => {
				return {
					path: item.path,
					message: item.message
				}
			})
		})
	})

}

export default validate;